<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>LCV Framework: bayer-lcv.c Quellcode</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
<link href="tabs.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Erzeugt von Doxygen 1.5.3 -->
<div class="tabs">
  <ul>
    <li><a href="index.html"><span>Hauptseite</span></a></li>
    <li><a href="classes.html"><span>Datenstrukturen</span></a></li>
    <li class="current"><a href="files.html"><span>Dateien</span></a></li>
  </ul>
</div>
<h1>bayer-lcv.c</h1><a href="bayer-lcv_8c.html">gehe zur Dokumentation dieser Datei</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 
<a name="l00002"></a>00002 <span class="comment">/***********************************************</span>
<a name="l00003"></a>00003 <span class="comment"> * cfa2bgr();</span>
<a name="l00004"></a>00004 <span class="comment"> *</span>
<a name="l00005"></a>00005 <span class="comment"> * Convert 8bpp RAW image data from CMOS Sensor </span>
<a name="l00006"></a>00006 <span class="comment"> * to 24bpp BGR image</span>
<a name="l00007"></a>00007 <span class="comment"> *</span>
<a name="l00008"></a>00008 <span class="comment"> * Input: point to RAW image buffer</span>
<a name="l00009"></a>00009 <span class="comment"> *        image width</span>
<a name="l00010"></a>00010 <span class="comment"> *        image height</span>
<a name="l00011"></a>00011 <span class="comment"> *</span>
<a name="l00012"></a>00012 <span class="comment"> * Output: pointer to new BGR image buffer</span>
<a name="l00013"></a>00013 <span class="comment"> *</span>
<a name="l00014"></a>00014 <span class="comment"> **********************************************/</span>
<a name="l00015"></a>00015 
<a name="l00016"></a>00016 <span class="preprocessor">#include &lt;sys/ioctl.h&gt;</span>
<a name="l00017"></a>00017 <span class="preprocessor">#include &lt;stdio.h&gt;</span>
<a name="l00018"></a>00018 <span class="preprocessor">#include &lt;stdlib.h&gt;</span>
<a name="l00019"></a>00019 <span class="preprocessor">#include &lt;fcntl.h&gt;</span>
<a name="l00020"></a>00020 <span class="preprocessor">#include &lt;linux/ioctl.h&gt;</span>
<a name="l00021"></a>00021 <span class="preprocessor">#include &lt;errno.h&gt;</span>
<a name="l00022"></a>00022 <span class="preprocessor">#include &lt;unistd.h&gt;</span>
<a name="l00023"></a>00023 <span class="preprocessor">#include &lt;getopt.h&gt;</span>
<a name="l00024"></a>00024 <span class="preprocessor">#include &lt;string.h&gt;</span>
<a name="l00025"></a>00025 <span class="preprocessor">#include &lt;strings.h&gt;</span>
<a name="l00026"></a>00026 
<a name="l00027"></a>00027 <span class="preprocessor">#include &lt;assert.h&gt;</span>
<a name="l00028"></a>00028 <span class="preprocessor">#include "<a class="code" href="bayer-lcv_8h.html">bayer-lcv.h</a>"</span>
<a name="l00029"></a>00029 
<a name="l00030"></a><a class="code" href="bayer-lcv_8c.html#ac42e714a968472db53b9b29bfe9e6ba">00030</a> <span class="preprocessor">#define INTDIVIDEBY2ROUND(x) ((x + 1) / 2)</span>
<a name="l00031"></a><a class="code" href="bayer-lcv_8c.html#2d3bb940d8d54bbe15a01aca8f68c88c">00031</a> <span class="preprocessor"></span><span class="preprocessor">#define INTDIVIDEBY3ROUND(x) ((x + 1) / 3)</span>
<a name="l00032"></a><a class="code" href="bayer-lcv_8c.html#40df06c100ea57dc9c149f2a12a7f90e">00032</a> <span class="preprocessor"></span><span class="preprocessor">#define INTDIVIDEBY4ROUND(x) ((x + 2) / 4)</span>
<a name="l00033"></a><a class="code" href="bayer-lcv_8c.html#1e58feb56979e2c69ab8bd0fcec33403">00033</a> <span class="preprocessor"></span><span class="preprocessor">#define INTDIVIDEBY8ROUND(x) ((x + 4) / 8)</span>
<a name="l00034"></a><a class="code" href="bayer-lcv_8c.html#4cc86401fbdb901680dee4a847fa3d94">00034</a> <span class="preprocessor"></span><span class="preprocessor">#define SATURATE2CHAR(x) (x &lt; 0 ? 0 : (x &gt; 255 ? 255 : x))</span>
<a name="l00035"></a><a class="code" href="bayer-lcv_8c.html#46f334971b3b75297177daaf93625502">00035</a> <span class="preprocessor"></span><span class="preprocessor">#define ISODD(x)         (x &amp; 0x1)</span>
<a name="l00036"></a>00036 <span class="preprocessor"></span>
<a name="l00037"></a>00037 
<a name="l00038"></a>00038 <span class="comment">// Set info on Bayer Pattern, i.e. where to find which color</span>
<a name="l00039"></a><a class="code" href="bayer-lcv_8c.html#1255d0173cbe449c0c28896d869d719b">00039</a> <a class="code" href="bayer-lcv_8h.html#1fcc96778794b059ae97b09a7ecf5f0e">Color</a> <a class="code" href="bayer-lcv_8c.html#1255d0173cbe449c0c28896d869d719b">m_FirstPixColor</a> = <a class="code" href="bayer-lcv_8h.html#55ecd4f2ec2ebfe8d5b0163e4ac2a9673f2a77ecd272aa6d6b5902faa5e5fc68">B</a>;
<a name="l00040"></a><a class="code" href="bayer-lcv_8c.html#e1a5361ee6973b743e0ecb7c2c522ceb">00040</a> <a class="code" href="bayer-lcv_8h.html#1fcc96778794b059ae97b09a7ecf5f0e">Color</a> <a class="code" href="bayer-lcv_8c.html#e1a5361ee6973b743e0ecb7c2c522ceb">m_SecondPixColor</a> = <a class="code" href="bayer-lcv_8h.html#55ecd4f2ec2ebfe8d5b0163e4ac2a9672fe993340f6abb2234e543cd427df70b">G</a>;
<a name="l00041"></a>00041 
<a name="l00042"></a><a class="code" href="bayer-lcv_8c.html#433d67b039529aee5d9dfe9a36b849a6">00042</a> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> * <a class="code" href="bayer-lcv_8c.html#433d67b039529aee5d9dfe9a36b849a6">cfa2bgr_AllocMem</a>(<span class="keywordtype">int</span> size)
<a name="l00043"></a>00043 {
<a name="l00044"></a>00044   <span class="comment">/* Allocate memory for the raw image and BMP Header */</span>
<a name="l00045"></a>00045   <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> *buffer = (<span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> *)malloc(size);
<a name="l00046"></a>00046   <span class="keywordflow">return</span> buffer;
<a name="l00047"></a>00047 }
<a name="l00048"></a>00048 
<a name="l00049"></a>00049 
<a name="l00050"></a>00050 
<a name="l00051"></a><a class="code" href="bayer-lcv_8h.html#591ee3e7fb0b3311c0e346160ce49a5f">00051</a> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span>* <a class="code" href="bayer-lcv_8c.html#591ee3e7fb0b3311c0e346160ce49a5f">cfa2bgr_DoBayerFiltering</a>(<span class="keywordtype">unsigned</span> <span class="keywordtype">char</span>* raw_buf, <span class="keywordtype">int</span> header_size, <span class="keywordtype">int</span> width, <span class="keywordtype">int</span> height)
<a name="l00052"></a>00052 <span class="comment">/* Used algorithm:</span>
<a name="l00053"></a>00053 <span class="comment">  Linear Interpolation with Laplacian second-order correction terms I.</span>
<a name="l00054"></a>00054 <span class="comment">  See http://scien.stanford.edu/class/psych221/projects/99/tingchen/main.htm</span>
<a name="l00055"></a>00055 <span class="comment"></span>
<a name="l00056"></a>00056 <span class="comment">  The output input has the following format: BGR</span>
<a name="l00057"></a>00057 <span class="comment">*/</span>
<a name="l00058"></a>00058 {
<a name="l00059"></a>00059        <span class="keywordtype">int</span> nRx, nRy, nGx, nGy, nBx, nBy;
<a name="l00060"></a>00060 
<a name="l00061"></a>00061        <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span>* pInputImage = raw_buf;
<a name="l00062"></a>00062        <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span>* pOutImageHeader = <a class="code" href="bayer-lcv_8c.html#433d67b039529aee5d9dfe9a36b849a6">cfa2bgr_AllocMem</a>(3*width*height + header_size);
<a name="l00063"></a>00063        <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span>* pOutImage   = (<span class="keywordtype">unsigned</span> <span class="keywordtype">char</span>*)(pOutImageHeader + header_size);
<a name="l00064"></a>00064        <span class="keywordtype">int</span>   nXSize      = width;
<a name="l00065"></a>00065        <span class="keywordtype">int</span>   nYSize      = height;
<a name="l00066"></a>00066        
<a name="l00067"></a>00067        <span class="comment">// Only for better debuging</span>
<a name="l00068"></a>00068        <span class="comment">// memset(pOutImage, 0, m_outputimage-&gt;getImageSizeInByte());</span>
<a name="l00069"></a>00069 
<a name="l00070"></a>00070        <a class="code" href="bayer-lcv_8c.html#1548ff298fb29b921f7124f62fd13e39">cfa2bgr_DetFirstPos</a>(&amp;nRx, &amp;nRy, &amp;nGx, &amp;nGy, &amp;nBx, &amp;nBy);
<a name="l00071"></a>00071 
<a name="l00072"></a>00072        <span class="comment">// Copy the pixel of input image that can be used without</span>
<a name="l00073"></a>00073        <span class="comment">// interpolation to the output pixels</span>
<a name="l00074"></a>00074        <span class="comment">//--------------------------------------------------------</span>
<a name="l00075"></a>00075 
<a name="l00076"></a>00076        <a class="code" href="bayer-lcv_8c.html#ea2573951d37d25d3e98d3aaf668ed18">cfa2bgr_CopyConstPix2Out</a>(pInputImage, pOutImage, nXSize, nYSize, nRx, nRy, <a class="code" href="bayer-lcv_8h.html#55ecd4f2ec2ebfe8d5b0163e4ac2a9671784b1a3d7cbd43c45ff82c72d05e4ae">R</a>);
<a name="l00077"></a>00077        <a class="code" href="bayer-lcv_8c.html#ea2573951d37d25d3e98d3aaf668ed18">cfa2bgr_CopyConstPix2Out</a>(pInputImage, pOutImage, nXSize, nYSize, nGx, nGy, <a class="code" href="bayer-lcv_8h.html#55ecd4f2ec2ebfe8d5b0163e4ac2a9672fe993340f6abb2234e543cd427df70b">G</a>);
<a name="l00078"></a>00078        <a class="code" href="bayer-lcv_8c.html#ea2573951d37d25d3e98d3aaf668ed18">cfa2bgr_CopyConstPix2Out</a>(pInputImage, pOutImage, nXSize, nYSize, nBx, nBy, <a class="code" href="bayer-lcv_8h.html#55ecd4f2ec2ebfe8d5b0163e4ac2a9673f2a77ecd272aa6d6b5902faa5e5fc68">B</a>);
<a name="l00079"></a>00079 
<a name="l00080"></a>00080        <span class="comment">// Interpolate</span>
<a name="l00081"></a>00081        <span class="comment">//------------</span>
<a name="l00082"></a>00082 
<a name="l00083"></a>00083        <a class="code" href="bayer-lcv_8c.html#d9ed7252b03ab300433b7c7798f203a7">cfa2bgr_InterpGreen</a>(pInputImage, pOutImage, nXSize, nYSize, nGx, nGy);
<a name="l00084"></a>00084        <a class="code" href="bayer-lcv_8c.html#bed4c40592605145d0a23d628580c301">cfa2bgr_InterpRedOrBlue</a>(pInputImage, pOutImage, nXSize, nYSize, nRx, nRy, 1);
<a name="l00085"></a>00085        <a class="code" href="bayer-lcv_8c.html#bed4c40592605145d0a23d628580c301">cfa2bgr_InterpRedOrBlue</a>(pInputImage, pOutImage, nXSize, nYSize, nBx, nBy, 0);
<a name="l00086"></a>00086 
<a name="l00087"></a>00087        <span class="keywordflow">return</span> pOutImageHeader;
<a name="l00088"></a>00088 }
<a name="l00089"></a>00089 
<a name="l00090"></a><a class="code" href="bayer-lcv_8h.html#1548ff298fb29b921f7124f62fd13e39">00090</a> <span class="keywordtype">void</span> <a class="code" href="bayer-lcv_8c.html#1548ff298fb29b921f7124f62fd13e39">cfa2bgr_DetFirstPos</a>(<span class="keywordtype">int</span>* nRx, <span class="keywordtype">int</span>* nRy, <span class="keywordtype">int</span>* nGx, <span class="keywordtype">int</span>* nGy, <span class="keywordtype">int</span>* nBx, <span class="keywordtype">int</span>* nBy)
<a name="l00091"></a>00091 {
<a name="l00092"></a>00092        <span class="keywordflow">if</span> (<a class="code" href="bayer-lcv_8c.html#1255d0173cbe449c0c28896d869d719b">m_FirstPixColor</a> == <a class="code" href="bayer-lcv_8h.html#55ecd4f2ec2ebfe8d5b0163e4ac2a9671784b1a3d7cbd43c45ff82c72d05e4ae">R</a>)       <span class="comment">// RGRG</span>
<a name="l00093"></a>00093        {                               <span class="comment">// GBGB</span>
<a name="l00094"></a>00094                *nRx = 0; *nRy = 0;
<a name="l00095"></a>00095                *nGx = 1; *nGy = 0;
<a name="l00096"></a>00096                *nBx = 1; *nBy = 1;
<a name="l00097"></a>00097        }
<a name="l00098"></a>00098        <span class="keywordflow">else</span> <span class="keywordflow">if</span> (<a class="code" href="bayer-lcv_8c.html#1255d0173cbe449c0c28896d869d719b">m_FirstPixColor</a> == <a class="code" href="bayer-lcv_8h.html#55ecd4f2ec2ebfe8d5b0163e4ac2a9673f2a77ecd272aa6d6b5902faa5e5fc68">B</a>)  <span class="comment">// BGBG</span>
<a name="l00099"></a>00099        {                               <span class="comment">// GRGR</span>
<a name="l00100"></a>00100                *nRx = 1; *nRy = 1;
<a name="l00101"></a>00101                *nGx = 1; *nGy = 0;
<a name="l00102"></a>00102                *nBx = 0; *nBy = 0;
<a name="l00103"></a>00103        }
<a name="l00104"></a>00104        <span class="keywordflow">else</span>
<a name="l00105"></a>00105        {
<a name="l00106"></a>00106                <span class="keywordflow">if</span> (<a class="code" href="bayer-lcv_8c.html#e1a5361ee6973b743e0ecb7c2c522ceb">m_SecondPixColor</a> == <a class="code" href="bayer-lcv_8h.html#55ecd4f2ec2ebfe8d5b0163e4ac2a9671784b1a3d7cbd43c45ff82c72d05e4ae">R</a>)  <span class="comment">// GRGR</span>
<a name="l00107"></a>00107                {                           <span class="comment">// BGBG</span>
<a name="l00108"></a>00108                        *nRx = 1; *nRy = 0;
<a name="l00109"></a>00109                        *nGx = 0; *nGy = 0;
<a name="l00110"></a>00110                        *nBx = 0; *nBy = 1;
<a name="l00111"></a>00111                }
<a name="l00112"></a>00112                <span class="keywordflow">else</span> <span class="keywordflow">if</span> (<a class="code" href="bayer-lcv_8c.html#e1a5361ee6973b743e0ecb7c2c522ceb">m_SecondPixColor</a> == <a class="code" href="bayer-lcv_8h.html#55ecd4f2ec2ebfe8d5b0163e4ac2a9673f2a77ecd272aa6d6b5902faa5e5fc68">B</a>)  <span class="comment">// GBGB</span>
<a name="l00113"></a>00113                {                                <span class="comment">// RGRG</span>
<a name="l00114"></a>00114                        *nRx = 0; *nRy = 1;
<a name="l00115"></a>00115                        *nGx = 0; *nGy = 0;
<a name="l00116"></a>00116                        *nBx = 1; *nBy = 0;
<a name="l00117"></a>00117                }
<a name="l00118"></a>00118        }
<a name="l00119"></a>00119 }
<a name="l00120"></a>00120 
<a name="l00121"></a><a class="code" href="bayer-lcv_8h.html#ea2573951d37d25d3e98d3aaf668ed18">00121</a> <span class="keywordtype">void</span> <a class="code" href="bayer-lcv_8c.html#ea2573951d37d25d3e98d3aaf668ed18">cfa2bgr_CopyConstPix2Out</a>(<span class="keywordtype">unsigned</span> <span class="keywordtype">char</span>* pInpData, <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span>* pOutData, <span class="keywordtype">int</span> nXSize, <span class="keywordtype">int</span> nYSize, <span class="keywordtype">int</span> nStartPixX, <span class="keywordtype">int</span> nStartPixY, <a class="code" href="bayer-lcv_8h.html#1fcc96778794b059ae97b09a7ecf5f0e">Color</a> Col)
<a name="l00122"></a>00122 {
<a name="l00123"></a>00123        <span class="keywordtype">int</span> i, j, k;
<a name="l00124"></a>00124        <span class="keywordtype">int</span> nCurLineInp, CurIndx;
<a name="l00125"></a>00125        <span class="keywordtype">int</span> nColOffset, nRuns;
<a name="l00126"></a>00126 
<a name="l00127"></a>00127        <span class="keywordtype">int</span> StartPixX[2];
<a name="l00128"></a>00128        <span class="keywordtype">int</span> StartPixY[2];
<a name="l00129"></a>00129        StartPixX[0] = nStartPixX;
<a name="l00130"></a>00130        StartPixY[0] = nStartPixY;
<a name="l00131"></a>00131 
<a name="l00132"></a>00132        <span class="comment">// Prepare values for different colors</span>
<a name="l00133"></a>00133        <span class="keywordflow">if</span> (Col == <a class="code" href="bayer-lcv_8h.html#55ecd4f2ec2ebfe8d5b0163e4ac2a9672fe993340f6abb2234e543cd427df70b">G</a>)
<a name="l00134"></a>00134        {
<a name="l00135"></a>00135                nRuns        = 2;
<a name="l00136"></a>00136                StartPixX[1] = nStartPixX == 0 ? 1 : 0;    <span class="comment">// Start pos. for 2. run</span>
<a name="l00137"></a>00137                StartPixY[1] = 1;
<a name="l00138"></a>00138                nColOffset   = <a class="code" href="bayer-lcv_8h.html#06fc87d81c62e9abb8790b6e5713c55b5f11449b9047629154a871fa1c07e48e">GOFFSET</a>;
<a name="l00139"></a>00139        }
<a name="l00140"></a>00140        <span class="keywordflow">else</span>
<a name="l00141"></a>00141        {
<a name="l00142"></a>00142                nRuns = 1;
<a name="l00143"></a>00143                <span class="keywordflow">if</span> (Col == <a class="code" href="bayer-lcv_8h.html#55ecd4f2ec2ebfe8d5b0163e4ac2a9673f2a77ecd272aa6d6b5902faa5e5fc68">B</a>)
<a name="l00144"></a>00144                        nColOffset = <a class="code" href="bayer-lcv_8h.html#06fc87d81c62e9abb8790b6e5713c55b5a3e5fec9864c188e63b852ffdd05a9f">BOFFSET</a>;
<a name="l00145"></a>00145                <span class="keywordflow">else</span>
<a name="l00146"></a>00146                        nColOffset = <a class="code" href="bayer-lcv_8h.html#06fc87d81c62e9abb8790b6e5713c55bc8a40a5091c6fad76cb9164876c6fc70">ROFFSET</a>;
<a name="l00147"></a>00147        }
<a name="l00148"></a>00148 
<a name="l00149"></a>00149        <span class="comment">// Copy pixels that are not interpolated</span>
<a name="l00150"></a>00150        <span class="keywordflow">for</span> (k = 0; k &lt; nRuns; k++)
<a name="l00151"></a>00151        {
<a name="l00152"></a>00152                <span class="keywordflow">for</span> (i = StartPixY[k]; i &lt; nYSize; i += 2)
<a name="l00153"></a>00153                {
<a name="l00154"></a>00154                        nCurLineInp = i * nXSize;
<a name="l00155"></a>00155                        <span class="keywordflow">for</span> (j = StartPixX[k]; j &lt; nXSize; j +=2)
<a name="l00156"></a>00156                        {
<a name="l00157"></a>00157                                CurIndx = nCurLineInp + j;
<a name="l00158"></a>00158                                pOutData[3 * CurIndx + nColOffset] = pInpData[CurIndx];
<a name="l00159"></a>00159                        }
<a name="l00160"></a>00160                }
<a name="l00161"></a>00161        }
<a name="l00162"></a>00162 }
<a name="l00163"></a>00163 
<a name="l00164"></a>00164 
<a name="l00165"></a><a class="code" href="bayer-lcv_8h.html#f32b188b68942e6dc498c28fde558b78">00165</a> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> <a class="code" href="bayer-lcv_8c.html#f32b188b68942e6dc498c28fde558b78">cfa2bgr_InterpCurGreen</a>(<span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> *pInpData, <span class="keywordtype">int</span> nCurIndx, <span class="keywordtype">int</span> nXSize)
<a name="l00166"></a>00166 {
<a name="l00167"></a>00167        <span class="comment">// Laplace horizontal and vertical</span>
<a name="l00168"></a>00168        <span class="keywordtype">int</span> nLapH, nLapV;
<a name="l00169"></a>00169        <span class="keywordtype">int</span> nDeltaH, nDeltaV;
<a name="l00170"></a>00170        <span class="keywordtype">int</span> nTmp, nOutVal;
<a name="l00171"></a>00171 
<a name="l00172"></a>00172        <span class="keywordtype">int</span> GW = pInpData[nCurIndx-1];        <span class="comment">// Green Color</span>
<a name="l00173"></a>00173        <span class="keywordtype">int</span> GE = pInpData[nCurIndx+1];        <span class="comment">// Green Color</span>
<a name="l00174"></a>00174        <span class="keywordtype">int</span> GN = pInpData[nCurIndx-nXSize];   <span class="comment">// Green Color</span>
<a name="l00175"></a>00175        <span class="keywordtype">int</span> GS = pInpData[nCurIndx+nXSize];   <span class="comment">// Green Color</span>
<a name="l00176"></a>00176 
<a name="l00177"></a>00177        nTmp  = 2 * pInpData[nCurIndx];
<a name="l00178"></a>00178        nLapH = nTmp - pInpData[nCurIndx - 2]        - pInpData[nCurIndx + 2];        <span class="comment">// Other colors</span>
<a name="l00179"></a>00179        nLapV = nTmp - pInpData[nCurIndx - 2*nXSize] - pInpData[nCurIndx + 2*nXSize]; <span class="comment">// Other colors</span>
<a name="l00180"></a>00180 
<a name="l00181"></a>00181        nDeltaH = abs(GW - GE) + abs(nLapH);
<a name="l00182"></a>00182        nDeltaV = abs(GN - GS) + abs(nLapV);
<a name="l00183"></a>00183 
<a name="l00184"></a>00184        <span class="keywordflow">if</span> (nDeltaH &lt; nDeltaV)
<a name="l00185"></a>00185        {
<a name="l00186"></a>00186                <span class="comment">// nOutVal = (GW + GE) / 2 + nLapH / 4;</span>
<a name="l00187"></a>00187                nOutVal = <a class="code" href="bayer-lcv_8c.html#40df06c100ea57dc9c149f2a12a7f90e">INTDIVIDEBY4ROUND</a>(2 * (GW + GE) + nLapH);
<a name="l00188"></a>00188        }
<a name="l00189"></a>00189        <span class="keywordflow">else</span> <span class="keywordflow">if</span> (nDeltaH &gt; nDeltaV)
<a name="l00190"></a>00190        {
<a name="l00191"></a>00191                <span class="comment">// nOutVal = (GN + GS) / 2 + nLapV / 4;</span>
<a name="l00192"></a>00192                nOutVal = <a class="code" href="bayer-lcv_8c.html#40df06c100ea57dc9c149f2a12a7f90e">INTDIVIDEBY4ROUND</a>(2 * (GN + GS) + nLapV);
<a name="l00193"></a>00193        }
<a name="l00194"></a>00194        <span class="keywordflow">else</span>
<a name="l00195"></a>00195        {
<a name="l00196"></a>00196                <span class="comment">// nOutVal = (GN + GE + GS + GW) / 4 + (nLapV + nLapH) / 8;</span>
<a name="l00197"></a>00197                nOutVal = <a class="code" href="bayer-lcv_8c.html#1e58feb56979e2c69ab8bd0fcec33403">INTDIVIDEBY8ROUND</a>(2 * (GN + GE + GS + GW) + (nLapV + nLapH));
<a name="l00198"></a>00198        }
<a name="l00199"></a>00199 
<a name="l00200"></a>00200        <span class="keywordflow">return</span> <a class="code" href="bayer-lcv_8c.html#4cc86401fbdb901680dee4a847fa3d94">SATURATE2CHAR</a>(nOutVal);
<a name="l00201"></a>00201 }
<a name="l00202"></a>00202 
<a name="l00203"></a><a class="code" href="bayer-lcv_8h.html#d9ed7252b03ab300433b7c7798f203a7">00203</a> <span class="keywordtype">void</span> <a class="code" href="bayer-lcv_8c.html#d9ed7252b03ab300433b7c7798f203a7">cfa2bgr_InterpGreen</a>(<span class="keywordtype">unsigned</span> <span class="keywordtype">char</span>* pInpData, <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span>* pOutData, <span class="keywordtype">int</span> nXSize, <span class="keywordtype">int</span> nYSize, <span class="keywordtype">int</span> nStartPixX, <span class="keywordtype">int</span> nStartPixY)
<a name="l00204"></a>00204 {
<a name="l00205"></a>00205        assert(nStartPixY == 0);
<a name="l00206"></a>00206 
<a name="l00207"></a>00207        <span class="keywordtype">int</span> i, j;
<a name="l00208"></a>00208        <span class="keywordtype">int</span> nCurLineInp, nCurIndx;                           <span class="comment">//     X</span>
<a name="l00209"></a>00209                                                         <span class="comment">//     G</span>
<a name="l00210"></a>00210        <span class="keywordtype">int</span> nStartX0 = nStartPixX == 0 ? 3 : 2;              <span class="comment">// X G X G X</span>
<a name="l00211"></a>00211        <span class="keywordtype">int</span> nStartX1 = nStartPixX == 0 ? 2 : 3;              <span class="comment">//     G</span>
<a name="l00212"></a>00212                                                         <span class="comment">//     X</span>
<a name="l00213"></a>00213        <span class="keywordflow">for</span> (i = 2; i &lt; nYSize-2; i += 2)
<a name="l00214"></a>00214        {
<a name="l00215"></a>00215                nCurLineInp = i * nXSize;
<a name="l00216"></a>00216                <span class="keywordflow">for</span> (j = nStartX0; j &lt; nXSize-2; j +=2)
<a name="l00217"></a>00217                {
<a name="l00218"></a>00218                        nCurIndx = nCurLineInp + j;
<a name="l00219"></a>00219                        pOutData[3 * nCurIndx + <a class="code" href="bayer-lcv_8h.html#06fc87d81c62e9abb8790b6e5713c55b5f11449b9047629154a871fa1c07e48e">GOFFSET</a>] = <a class="code" href="bayer-lcv_8c.html#f32b188b68942e6dc498c28fde558b78">cfa2bgr_InterpCurGreen</a>(pInpData, nCurIndx, nXSize);
<a name="l00220"></a>00220                }
<a name="l00221"></a>00221                nCurLineInp = (i+1) * nXSize;
<a name="l00222"></a>00222                <span class="keywordflow">for</span> (j = nStartX1; j &lt; nXSize-2; j +=2)
<a name="l00223"></a>00223                {
<a name="l00224"></a>00224                        nCurIndx = nCurLineInp + j;
<a name="l00225"></a>00225                        pOutData[3 * nCurIndx + <a class="code" href="bayer-lcv_8h.html#06fc87d81c62e9abb8790b6e5713c55b5f11449b9047629154a871fa1c07e48e">GOFFSET</a>] = <a class="code" href="bayer-lcv_8c.html#f32b188b68942e6dc498c28fde558b78">cfa2bgr_InterpCurGreen</a>(pInpData, nCurIndx, nXSize);
<a name="l00226"></a>00226                }
<a name="l00227"></a>00227        }
<a name="l00228"></a>00228 
<a name="l00229"></a>00229        <span class="comment">// Border must handled separate.</span>
<a name="l00230"></a>00230        <a class="code" href="bayer-lcv_8c.html#687bac14e38d8b6549839b5d435b99c1">cfa2bgr_InterpGreenBorder</a>(pInpData, pOutData, nXSize, nYSize, nStartPixX, nStartPixY);
<a name="l00231"></a>00231 }
<a name="l00232"></a>00232 
<a name="l00233"></a>00233 
<a name="l00234"></a><a class="code" href="bayer-lcv_8h.html#687bac14e38d8b6549839b5d435b99c1">00234</a> <span class="keywordtype">void</span> <a class="code" href="bayer-lcv_8c.html#687bac14e38d8b6549839b5d435b99c1">cfa2bgr_InterpGreenBorder</a>(<span class="keywordtype">unsigned</span> <span class="keywordtype">char</span>* pInpData, <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span>* pOutData, <span class="keywordtype">int</span> nXSize, <span class="keywordtype">int</span> nYSize, <span class="keywordtype">int</span> nStartPixX, <span class="keywordtype">int</span> nStartPixY)
<a name="l00235"></a>00235 <span class="comment">/* Only linear interpolation</span>
<a name="l00236"></a>00236 <span class="comment">*/</span>
<a name="l00237"></a>00237 {
<a name="l00238"></a>00238        <span class="keywordtype">int</span>  i;
<a name="l00239"></a>00239        <span class="keywordtype">int</span>  nCurVal, nCurIndx;
<a name="l00240"></a>00240        <span class="keywordtype">int</span>  nStartX, nStartY;
<a name="l00241"></a>00241        <span class="keywordtype">int</span> isOddXSize = <a class="code" href="bayer-lcv_8c.html#46f334971b3b75297177daaf93625502">ISODD</a>(nXSize);
<a name="l00242"></a>00242        <span class="keywordtype">int</span> isOddYSize = <a class="code" href="bayer-lcv_8c.html#46f334971b3b75297177daaf93625502">ISODD</a>(nYSize);
<a name="l00243"></a>00243 
<a name="l00244"></a>00244        <span class="comment">// First Line</span>
<a name="l00245"></a>00245        <span class="keywordflow">for</span> (i = nStartPixX+1; i &lt; nXSize-1; i +=2)
<a name="l00246"></a>00246        {
<a name="l00247"></a>00247                nCurVal = pInpData[i-1] + pInpData[i+1] + pInpData[i+nXSize];
<a name="l00248"></a>00248                pOutData[3 * i + <a class="code" href="bayer-lcv_8h.html#06fc87d81c62e9abb8790b6e5713c55b5f11449b9047629154a871fa1c07e48e">GOFFSET</a>] = <a class="code" href="bayer-lcv_8c.html#2d3bb940d8d54bbe15a01aca8f68c88c">INTDIVIDEBY3ROUND</a>(nCurVal);
<a name="l00249"></a>00249        }
<a name="l00250"></a>00250 
<a name="l00251"></a>00251        <span class="comment">// Second Line</span>
<a name="l00252"></a>00252        nStartX = nStartPixX == 0 ? 2 : 1;
<a name="l00253"></a>00253        <span class="keywordflow">for</span> (i = nStartX; i &lt; nXSize-1; i +=2)
<a name="l00254"></a>00254        {
<a name="l00255"></a>00255                nCurIndx = nXSize + i;
<a name="l00256"></a>00256                nCurVal  = pInpData[nCurIndx-1] + pInpData[nCurIndx+1] + pInpData[nCurIndx-nXSize] + pInpData[nCurIndx+nXSize];
<a name="l00257"></a>00257                pOutData[3 * nCurIndx + <a class="code" href="bayer-lcv_8h.html#06fc87d81c62e9abb8790b6e5713c55b5f11449b9047629154a871fa1c07e48e">GOFFSET</a>] = <a class="code" href="bayer-lcv_8c.html#40df06c100ea57dc9c149f2a12a7f90e">INTDIVIDEBY4ROUND</a>(nCurVal);
<a name="l00258"></a>00258        }
<a name="l00259"></a>00259 
<a name="l00260"></a>00260        <span class="comment">// First Column</span>
<a name="l00261"></a>00261        nStartY = nStartPixX == 0 ? 1: 2;
<a name="l00262"></a>00262        <span class="keywordflow">for</span> (i = nStartY; i &lt; nYSize-1; i +=2)
<a name="l00263"></a>00263        {
<a name="l00264"></a>00264                nCurIndx = i * nXSize;
<a name="l00265"></a>00265                nCurVal  = pInpData[nCurIndx-nXSize] + pInpData[nCurIndx+nXSize] + pInpData[nCurIndx+1];
<a name="l00266"></a>00266                pOutData[3 * nCurIndx + <a class="code" href="bayer-lcv_8h.html#06fc87d81c62e9abb8790b6e5713c55b5f11449b9047629154a871fa1c07e48e">GOFFSET</a>] = <a class="code" href="bayer-lcv_8c.html#2d3bb940d8d54bbe15a01aca8f68c88c">INTDIVIDEBY3ROUND</a>(nCurVal);
<a name="l00267"></a>00267        }
<a name="l00268"></a>00268 
<a name="l00269"></a>00269        <span class="comment">// Second Column</span>
<a name="l00270"></a>00270        nStartY = nStartPixX == 0 ? 2: 1;
<a name="l00271"></a>00271        <span class="keywordflow">for</span> (i = nStartY; i &lt; nYSize-1; i +=2)
<a name="l00272"></a>00272        {
<a name="l00273"></a>00273                nCurIndx = i * nXSize + 1;
<a name="l00274"></a>00274                nCurVal  = pInpData[nCurIndx-nXSize] + pInpData[nCurIndx+nXSize] + pInpData[nCurIndx-1] + pInpData[nCurIndx+1];
<a name="l00275"></a>00275                pOutData[3 * nCurIndx + <a class="code" href="bayer-lcv_8h.html#06fc87d81c62e9abb8790b6e5713c55b5f11449b9047629154a871fa1c07e48e">GOFFSET</a>] = <a class="code" href="bayer-lcv_8c.html#40df06c100ea57dc9c149f2a12a7f90e">INTDIVIDEBY4ROUND</a>(nCurVal);
<a name="l00276"></a>00276        }
<a name="l00277"></a>00277 
<a name="l00278"></a>00278        <span class="comment">// Top left corner</span>
<a name="l00279"></a>00279        <span class="keywordflow">if</span> (nStartPixX &gt; 0)
<a name="l00280"></a>00280        {
<a name="l00281"></a>00281                nCurVal = pInpData[1] + pInpData[nXSize];
<a name="l00282"></a>00282                pOutData[0 + <a class="code" href="bayer-lcv_8h.html#06fc87d81c62e9abb8790b6e5713c55b5f11449b9047629154a871fa1c07e48e">GOFFSET</a>] = <a class="code" href="bayer-lcv_8c.html#ac42e714a968472db53b9b29bfe9e6ba">INTDIVIDEBY2ROUND</a>(nCurVal);
<a name="l00283"></a>00283        }
<a name="l00284"></a>00284 
<a name="l00285"></a>00285        <span class="comment">// Last Line</span>
<a name="l00286"></a>00286        <span class="keywordflow">if</span> (   nStartPixX == 0 &amp;&amp; isOddYSize
<a name="l00287"></a>00287                || nStartPixX == 1 &amp;&amp; !isOddYSize)
<a name="l00288"></a>00288                nStartX = 1;
<a name="l00289"></a>00289        <span class="keywordflow">else</span>
<a name="l00290"></a>00290                nStartX = 2;
<a name="l00291"></a>00291        <span class="keywordflow">for</span> (i = nStartX; i &lt; nXSize-1; i +=2)
<a name="l00292"></a>00292        {
<a name="l00293"></a>00293                nCurIndx = nXSize * (nYSize - 1) + i;
<a name="l00294"></a>00294                nCurVal  = pInpData[nCurIndx-1] + pInpData[nCurIndx+1] + pInpData[nCurIndx-nXSize];
<a name="l00295"></a>00295                pOutData[3 * nCurIndx + <a class="code" href="bayer-lcv_8h.html#06fc87d81c62e9abb8790b6e5713c55b5f11449b9047629154a871fa1c07e48e">GOFFSET</a>] = <a class="code" href="bayer-lcv_8c.html#2d3bb940d8d54bbe15a01aca8f68c88c">INTDIVIDEBY3ROUND</a>(nCurVal);
<a name="l00296"></a>00296        }
<a name="l00297"></a>00297 
<a name="l00298"></a>00298        <span class="comment">// Second last Line</span>
<a name="l00299"></a>00299        <span class="keywordflow">if</span> (   nStartPixX == 0 &amp;&amp; isOddYSize
<a name="l00300"></a>00300                || nStartPixX == 1 &amp;&amp; !isOddYSize)
<a name="l00301"></a>00301                nStartX = 2;
<a name="l00302"></a>00302        <span class="keywordflow">else</span>
<a name="l00303"></a>00303                nStartX = 1;
<a name="l00304"></a>00304        <span class="keywordflow">for</span> (i = nStartX; i &lt; nXSize-1; i +=2)
<a name="l00305"></a>00305        {
<a name="l00306"></a>00306                nCurIndx = nXSize * (nYSize - 2) + i;
<a name="l00307"></a>00307                nCurVal  = pInpData[nCurIndx-1] + pInpData[nCurIndx+1] + pInpData[nCurIndx-nXSize] + pInpData[nCurIndx+nXSize];
<a name="l00308"></a>00308                pOutData[3 * nCurIndx + <a class="code" href="bayer-lcv_8h.html#06fc87d81c62e9abb8790b6e5713c55b5f11449b9047629154a871fa1c07e48e">GOFFSET</a>] = <a class="code" href="bayer-lcv_8c.html#40df06c100ea57dc9c149f2a12a7f90e">INTDIVIDEBY4ROUND</a>(nCurVal);
<a name="l00309"></a>00309        }
<a name="l00310"></a>00310 
<a name="l00311"></a>00311        <span class="comment">// Bottom left corner</span>
<a name="l00312"></a>00312        <span class="keywordflow">if</span> (   nStartPixX == 1 &amp;&amp; isOddYSize
<a name="l00313"></a>00313                || nStartPixX == 0 &amp;&amp; !isOddYSize)
<a name="l00314"></a>00314        {
<a name="l00315"></a>00315                nCurVal = pInpData[(nYSize-2) * nXSize] + pInpData[(nYSize-1) * nXSize + 1];
<a name="l00316"></a>00316                pOutData[3 * nXSize * (nYSize - 1) + <a class="code" href="bayer-lcv_8h.html#06fc87d81c62e9abb8790b6e5713c55b5f11449b9047629154a871fa1c07e48e">GOFFSET</a>] = <a class="code" href="bayer-lcv_8c.html#ac42e714a968472db53b9b29bfe9e6ba">INTDIVIDEBY2ROUND</a>(nCurVal);
<a name="l00317"></a>00317        }
<a name="l00318"></a>00318 
<a name="l00319"></a>00319        <span class="comment">// Last Column</span>
<a name="l00320"></a>00320        <span class="keywordflow">if</span> (   nStartPixX == 0 &amp;&amp; isOddXSize
<a name="l00321"></a>00321                || nStartPixX == 1 &amp;&amp; !isOddXSize)
<a name="l00322"></a>00322                nStartY = 1;
<a name="l00323"></a>00323        <span class="keywordflow">else</span>
<a name="l00324"></a>00324                nStartY = 2;
<a name="l00325"></a>00325        <span class="keywordflow">for</span> (i = nStartY; i &lt; nYSize-1; i +=2)
<a name="l00326"></a>00326        {
<a name="l00327"></a>00327                nCurIndx = i * nXSize + nXSize - 1;
<a name="l00328"></a>00328                nCurVal  = pInpData[nCurIndx-nXSize] + pInpData[nCurIndx+nXSize] + pInpData[nCurIndx-1];
<a name="l00329"></a>00329                pOutData[3 * nCurIndx + <a class="code" href="bayer-lcv_8h.html#06fc87d81c62e9abb8790b6e5713c55b5f11449b9047629154a871fa1c07e48e">GOFFSET</a>] = <a class="code" href="bayer-lcv_8c.html#2d3bb940d8d54bbe15a01aca8f68c88c">INTDIVIDEBY3ROUND</a>(nCurVal);
<a name="l00330"></a>00330        }
<a name="l00331"></a>00331 
<a name="l00332"></a>00332        <span class="comment">// Second last Column</span>
<a name="l00333"></a>00333        <span class="keywordflow">if</span> (   nStartPixX == 0 &amp;&amp; isOddXSize
<a name="l00334"></a>00334                || nStartPixX == 1 &amp;&amp; !isOddXSize)
<a name="l00335"></a>00335                nStartY = 2;
<a name="l00336"></a>00336        <span class="keywordflow">else</span>
<a name="l00337"></a>00337                nStartY = 1;
<a name="l00338"></a>00338        <span class="keywordflow">for</span> (i = nStartY; i &lt; nYSize-1; i +=2)
<a name="l00339"></a>00339        {
<a name="l00340"></a>00340                nCurIndx = i * nXSize + nXSize - 2;
<a name="l00341"></a>00341                nCurVal  = pInpData[nCurIndx-nXSize] + pInpData[nCurIndx+nXSize] + pInpData[nCurIndx-1] + pInpData[nCurIndx+1];
<a name="l00342"></a>00342                pOutData[3 * nCurIndx + <a class="code" href="bayer-lcv_8h.html#06fc87d81c62e9abb8790b6e5713c55b5f11449b9047629154a871fa1c07e48e">GOFFSET</a>] = <a class="code" href="bayer-lcv_8c.html#40df06c100ea57dc9c149f2a12a7f90e">INTDIVIDEBY4ROUND</a>(nCurVal);
<a name="l00343"></a>00343        }
<a name="l00344"></a>00344 
<a name="l00345"></a>00345        <span class="comment">// Top right pixel</span>
<a name="l00346"></a>00346        <span class="keywordflow">if</span> (   nStartPixX == 0 &amp;&amp; !isOddXSize
<a name="l00347"></a>00347                || nStartPixY == 1 &amp;&amp; isOddXSize)
<a name="l00348"></a>00348        {
<a name="l00349"></a>00349                nCurVal = pInpData[nXSize-2] + pInpData[2 * nXSize - 1];
<a name="l00350"></a>00350                pOutData[3 * (nXSize - 1) + <a class="code" href="bayer-lcv_8h.html#06fc87d81c62e9abb8790b6e5713c55b5f11449b9047629154a871fa1c07e48e">GOFFSET</a>] = <a class="code" href="bayer-lcv_8c.html#ac42e714a968472db53b9b29bfe9e6ba">INTDIVIDEBY2ROUND</a>(nCurVal);
<a name="l00351"></a>00351        }
<a name="l00352"></a>00352 
<a name="l00353"></a>00353        <span class="comment">// Bottom right pixel</span>
<a name="l00354"></a>00354        <span class="keywordflow">if</span> (   nStartPixX == 0 &amp;&amp; (isOddXSize &amp;&amp; !isOddYSize || isOddYSize  &amp;&amp; !isOddXSize)
<a name="l00355"></a>00355                || nStartPixX == 1 &amp;&amp; (isOddXSize &amp;&amp; isOddYSize  || !isOddYSize &amp;&amp; !isOddXSize))
<a name="l00356"></a>00356        {
<a name="l00357"></a>00357                nCurVal = pInpData[nYSize * nXSize - 2] + pInpData[(nYSize - 1) * nXSize - 1];
<a name="l00358"></a>00358                pOutData[3 * (nXSize * nYSize - 1) + <a class="code" href="bayer-lcv_8h.html#06fc87d81c62e9abb8790b6e5713c55b5f11449b9047629154a871fa1c07e48e">GOFFSET</a>] = <a class="code" href="bayer-lcv_8c.html#ac42e714a968472db53b9b29bfe9e6ba">INTDIVIDEBY2ROUND</a>(nCurVal);
<a name="l00359"></a>00359        }
<a name="l00360"></a>00360 }
<a name="l00361"></a>00361 
<a name="l00362"></a><a class="code" href="bayer-lcv_8h.html#d47d48e05330c7fc5e7a0d4b28e4d2b8">00362</a> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> <a class="code" href="bayer-lcv_8c.html#d47d48e05330c7fc5e7a0d4b28e4d2b8">cfa2bgr_InterpCurRedOrBlueDiag</a>(<span class="keywordtype">unsigned</span> <span class="keywordtype">char</span>* pInpData, <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span>* pOutData, <span class="keywordtype">int</span> nCurIndx, <span class="keywordtype">int</span> nXSize)
<a name="l00363"></a>00363 {
<a name="l00364"></a>00364        <span class="comment">// Laplace horizontal and vertical</span>
<a name="l00365"></a>00365        <span class="keywordtype">int</span> nLapN, nLapP;
<a name="l00366"></a>00366        <span class="keywordtype">int</span> nDeltaN, nDeltaP;
<a name="l00367"></a>00367        <span class="keywordtype">int</span> nTmp, nOutVal;
<a name="l00368"></a>00368 
<a name="l00369"></a>00369        <span class="keywordtype">int</span> CNW = pInpData[nCurIndx-1-nXSize];   <span class="comment">// Current Color</span>
<a name="l00370"></a>00370        <span class="keywordtype">int</span> CNE = pInpData[nCurIndx+1-nXSize];   <span class="comment">// Current Color</span>
<a name="l00371"></a>00371        <span class="keywordtype">int</span> CSE = pInpData[nCurIndx+1+nXSize];   <span class="comment">// Current Color</span>
<a name="l00372"></a>00372        <span class="keywordtype">int</span> CSW = pInpData[nCurIndx-1+nXSize];   <span class="comment">// Current Color</span>
<a name="l00373"></a>00373 
<a name="l00374"></a>00374        nTmp  = 2 * pOutData[3 * nCurIndx + <a class="code" href="bayer-lcv_8h.html#06fc87d81c62e9abb8790b6e5713c55b5f11449b9047629154a871fa1c07e48e">GOFFSET</a>];
<a name="l00375"></a>00375        nLapN = nTmp - pOutData[3 * (nCurIndx-1-nXSize) + <a class="code" href="bayer-lcv_8h.html#06fc87d81c62e9abb8790b6e5713c55b5f11449b9047629154a871fa1c07e48e">GOFFSET</a>] - pOutData[3 * (nCurIndx+1+nXSize) + <a class="code" href="bayer-lcv_8h.html#06fc87d81c62e9abb8790b6e5713c55b5f11449b9047629154a871fa1c07e48e">GOFFSET</a>]; <span class="comment">// Green color</span>
<a name="l00376"></a>00376        nLapP = nTmp - pOutData[3 * (nCurIndx+1-nXSize) + <a class="code" href="bayer-lcv_8h.html#06fc87d81c62e9abb8790b6e5713c55b5f11449b9047629154a871fa1c07e48e">GOFFSET</a>] - pOutData[3 * (nCurIndx-1+nXSize) + <a class="code" href="bayer-lcv_8h.html#06fc87d81c62e9abb8790b6e5713c55b5f11449b9047629154a871fa1c07e48e">GOFFSET</a>]; <span class="comment">// Green color</span>
<a name="l00377"></a>00377 
<a name="l00378"></a>00378        nDeltaN = abs(CNW - CSE) + abs(nLapN);
<a name="l00379"></a>00379        nDeltaP = abs(CNE - CSW) + abs(nLapP);
<a name="l00380"></a>00380 
<a name="l00381"></a>00381        <span class="keywordflow">if</span> (nDeltaN &lt; nDeltaP)
<a name="l00382"></a>00382        {
<a name="l00383"></a>00383                <span class="comment">// nOutVal = (CNW + CSE)/2 + nLapN/2;</span>
<a name="l00384"></a>00384                nOutVal = <a class="code" href="bayer-lcv_8c.html#ac42e714a968472db53b9b29bfe9e6ba">INTDIVIDEBY2ROUND</a>(CNW + CSE + nLapN);
<a name="l00385"></a>00385        }
<a name="l00386"></a>00386        <span class="keywordflow">else</span> <span class="keywordflow">if</span> (nDeltaN &gt; nDeltaP)
<a name="l00387"></a>00387        {
<a name="l00388"></a>00388                <span class="comment">// nOutVal = (CNE + CSW)/2 + nLapP/2;</span>
<a name="l00389"></a>00389                nOutVal = <a class="code" href="bayer-lcv_8c.html#ac42e714a968472db53b9b29bfe9e6ba">INTDIVIDEBY2ROUND</a>(CNE + CSW + nLapP);
<a name="l00390"></a>00390        }
<a name="l00391"></a>00391        <span class="keywordflow">else</span>
<a name="l00392"></a>00392        {
<a name="l00393"></a>00393                <span class="comment">// nOutVal = (CNW + CNE + CSE + CSW) / 4 + (nLapV + nLapH) / 4;</span>
<a name="l00394"></a>00394                nOutVal = <a class="code" href="bayer-lcv_8c.html#40df06c100ea57dc9c149f2a12a7f90e">INTDIVIDEBY4ROUND</a>(CNW + CNE + CSE + CSW + nLapN + nLapP);
<a name="l00395"></a>00395        }
<a name="l00396"></a>00396 
<a name="l00397"></a>00397        <span class="keywordflow">return</span> <a class="code" href="bayer-lcv_8c.html#4cc86401fbdb901680dee4a847fa3d94">SATURATE2CHAR</a>(nOutVal);
<a name="l00398"></a>00398 
<a name="l00399"></a>00399 }
<a name="l00400"></a>00400 
<a name="l00401"></a>00401 
<a name="l00402"></a><a class="code" href="bayer-lcv_8h.html#bed4c40592605145d0a23d628580c301">00402</a> <span class="keywordtype">void</span> <a class="code" href="bayer-lcv_8c.html#bed4c40592605145d0a23d628580c301">cfa2bgr_InterpRedOrBlue</a>(<span class="keywordtype">unsigned</span> <span class="keywordtype">char</span>* pInpData, <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span>* pOutData, <span class="keywordtype">int</span> nXSize, <span class="keywordtype">int</span> nYSize, <span class="keywordtype">int</span> nStartPixX, <span class="keywordtype">int</span> nStartPixY, <span class="keywordtype">int</span> isRed)
<a name="l00403"></a>00403 {
<a name="l00404"></a>00404        <span class="keywordtype">int</span> i, j;
<a name="l00405"></a>00405        <span class="keywordtype">int</span> nCurLineInp, nCurIndx;
<a name="l00406"></a>00406        <span class="keywordtype">int</span> nCurVal;
<a name="l00407"></a>00407        <span class="keywordtype">int</span> nColOffset = isRed ? <a class="code" href="bayer-lcv_8h.html#06fc87d81c62e9abb8790b6e5713c55bc8a40a5091c6fad76cb9164876c6fc70">ROFFSET</a> : <a class="code" href="bayer-lcv_8h.html#06fc87d81c62e9abb8790b6e5713c55b5a3e5fec9864c188e63b852ffdd05a9f">BOFFSET</a>;
<a name="l00408"></a>00408        <span class="keywordtype">int</span> nStartX0, nStartX1, nStartX2;
<a name="l00409"></a>00409        <span class="keywordtype">int</span> nStartY0, nStartY1, nStartY2;
<a name="l00410"></a>00410 
<a name="l00411"></a>00411        <span class="keywordflow">if</span> (nStartPixX == 0)
<a name="l00412"></a>00412        {
<a name="l00413"></a>00413                nStartX0 = 0;
<a name="l00414"></a>00414                nStartX1 = 1;
<a name="l00415"></a>00415                nStartX2 = 1;
<a name="l00416"></a>00416        }
<a name="l00417"></a>00417        <span class="keywordflow">else</span>
<a name="l00418"></a>00418        {
<a name="l00419"></a>00419                nStartX0 = 1;
<a name="l00420"></a>00420                nStartX1 = 2;
<a name="l00421"></a>00421                nStartX2 = 2;
<a name="l00422"></a>00422        }
<a name="l00423"></a>00423 
<a name="l00424"></a>00424        <span class="keywordflow">if</span> (nStartPixY == 0)
<a name="l00425"></a>00425        {
<a name="l00426"></a>00426                nStartY0 = 1;
<a name="l00427"></a>00427                nStartY1 = 0;
<a name="l00428"></a>00428                nStartY2 = 1;
<a name="l00429"></a>00429        }
<a name="l00430"></a>00430        <span class="keywordflow">else</span>
<a name="l00431"></a>00431        {
<a name="l00432"></a>00432                nStartY0 = 2;
<a name="l00433"></a>00433                nStartY1 = 1;
<a name="l00434"></a>00434                nStartY2 = 2;
<a name="l00435"></a>00435        }
<a name="l00436"></a>00436 
<a name="l00437"></a>00437        <span class="keywordflow">for</span> (i = nStartY0; i &lt; nYSize-1; i += 2)        <span class="comment">//  R      B</span>
<a name="l00438"></a>00438        {                                               <span class="comment">//  G  or  G</span>
<a name="l00439"></a>00439                nCurLineInp = i * nXSize;                   <span class="comment">//  R      B</span>
<a name="l00440"></a>00440                <span class="keywordflow">for</span> (j = nStartX0; j &lt; nXSize; j += 2)
<a name="l00441"></a>00441                {
<a name="l00442"></a>00442                        nCurIndx =  nCurLineInp + j;
<a name="l00443"></a>00443                        nCurVal  =  2 * (pInpData[nCurIndx-nXSize] + pInpData[nCurIndx+nXSize]);                                                     <span class="comment">// Current Color</span>
<a name="l00444"></a>00444                        nCurVal  += 2 * pInpData[nCurIndx] - pOutData[3 * (nCurIndx-nXSize) + <a class="code" href="bayer-lcv_8h.html#06fc87d81c62e9abb8790b6e5713c55b5f11449b9047629154a871fa1c07e48e">GOFFSET</a>] - pOutData[3 * (nCurIndx+nXSize) + <a class="code" href="bayer-lcv_8h.html#06fc87d81c62e9abb8790b6e5713c55b5f11449b9047629154a871fa1c07e48e">GOFFSET</a>];  <span class="comment">// Green Color</span>
<a name="l00445"></a>00445                        nCurVal  = <a class="code" href="bayer-lcv_8c.html#40df06c100ea57dc9c149f2a12a7f90e">INTDIVIDEBY4ROUND</a>(nCurVal);
<a name="l00446"></a>00446                        pOutData[3 * nCurIndx + nColOffset] = <a class="code" href="bayer-lcv_8c.html#4cc86401fbdb901680dee4a847fa3d94">SATURATE2CHAR</a>(nCurVal);
<a name="l00447"></a>00447                }
<a name="l00448"></a>00448        }
<a name="l00449"></a>00449 
<a name="l00450"></a>00450        <span class="keywordflow">for</span> (i = nStartY1; i &lt; nYSize; i +=2)         <span class="comment">// R G R   or    B G B</span>
<a name="l00451"></a>00451        {
<a name="l00452"></a>00452                nCurLineInp = i * nXSize;
<a name="l00453"></a>00453                <span class="keywordflow">for</span> (j = nStartX1; j &lt; nXSize-1; j += 2)
<a name="l00454"></a>00454                {
<a name="l00455"></a>00455                        nCurIndx =  nCurLineInp + j;
<a name="l00456"></a>00456                        nCurVal  =  2 * (pInpData[nCurIndx-1] + pInpData[nCurIndx+1]);                                         <span class="comment">// Current Color</span>
<a name="l00457"></a>00457                        nCurVal  += 2 * pInpData[nCurIndx] - pOutData[3 * (nCurIndx-1) + <a class="code" href="bayer-lcv_8h.html#06fc87d81c62e9abb8790b6e5713c55b5f11449b9047629154a871fa1c07e48e">GOFFSET</a>] - pOutData[3 * (nCurIndx+1) + <a class="code" href="bayer-lcv_8h.html#06fc87d81c62e9abb8790b6e5713c55b5f11449b9047629154a871fa1c07e48e">GOFFSET</a>];  <span class="comment">// Green Color</span>
<a name="l00458"></a>00458                        nCurVal  = <a class="code" href="bayer-lcv_8c.html#40df06c100ea57dc9c149f2a12a7f90e">INTDIVIDEBY4ROUND</a>(nCurVal);
<a name="l00459"></a>00459                        pOutData[3 * nCurIndx + nColOffset] = <a class="code" href="bayer-lcv_8c.html#4cc86401fbdb901680dee4a847fa3d94">SATURATE2CHAR</a>(nCurVal);
<a name="l00460"></a>00460                }
<a name="l00461"></a>00461        }
<a name="l00462"></a>00462 
<a name="l00463"></a>00463        <span class="keywordflow">for</span> (i = nStartY2; i &lt; nYSize-1; i +=2)         <span class="comment">// R G R      B G B</span>
<a name="l00464"></a>00464        {                                               <span class="comment">// G B G  or  G R G</span>
<a name="l00465"></a>00465                nCurLineInp = i * nXSize;                   <span class="comment">// R G R      B G B</span>
<a name="l00466"></a>00466                <span class="keywordflow">for</span> (j = nStartX2; j &lt; nXSize-1; j += 2)
<a name="l00467"></a>00467                {
<a name="l00468"></a>00468                        nCurIndx =  nCurLineInp + j;
<a name="l00469"></a>00469                        pOutData[3 * nCurIndx + nColOffset] = <a class="code" href="bayer-lcv_8c.html#d47d48e05330c7fc5e7a0d4b28e4d2b8">cfa2bgr_InterpCurRedOrBlueDiag</a>(pInpData, pOutData, nCurIndx, nXSize);
<a name="l00470"></a>00470                }
<a name="l00471"></a>00471        }
<a name="l00472"></a>00472 
<a name="l00473"></a>00473        <span class="comment">// Border must handled separate</span>
<a name="l00474"></a>00474        <a class="code" href="bayer-lcv_8c.html#daf63759293e4aa8e8225e041b50e8e4">cfa2bgr_InterpRedOrBlueBorder</a>(pInpData, pOutData, nXSize, nYSize, nStartPixX, nStartPixY, isRed);
<a name="l00475"></a>00475 }
<a name="l00476"></a>00476 
<a name="l00477"></a>00477 
<a name="l00478"></a><a class="code" href="bayer-lcv_8h.html#daf63759293e4aa8e8225e041b50e8e4">00478</a> <span class="keywordtype">void</span> <a class="code" href="bayer-lcv_8c.html#daf63759293e4aa8e8225e041b50e8e4">cfa2bgr_InterpRedOrBlueBorder</a>(<span class="keywordtype">unsigned</span> <span class="keywordtype">char</span>* pInpData, <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span>* pOutData, <span class="keywordtype">int</span> nXSize, <span class="keywordtype">int</span> nYSize, <span class="keywordtype">int</span> nStartPixX, <span class="keywordtype">int</span> nStartPixY, <span class="keywordtype">int</span> isRed)
<a name="l00479"></a>00479 <span class="comment">/* Copy values from the neighbour line or column in the output image.</span>
<a name="l00480"></a>00480 <span class="comment">*/</span>
<a name="l00481"></a>00481 {
<a name="l00482"></a>00482        <span class="keywordtype">int</span>  nColOffset = isRed ? <a class="code" href="bayer-lcv_8h.html#06fc87d81c62e9abb8790b6e5713c55bc8a40a5091c6fad76cb9164876c6fc70">ROFFSET</a> : <a class="code" href="bayer-lcv_8h.html#06fc87d81c62e9abb8790b6e5713c55b5a3e5fec9864c188e63b852ffdd05a9f">BOFFSET</a>;
<a name="l00483"></a>00483        <span class="keywordtype">int</span> isOddXSize = <a class="code" href="bayer-lcv_8c.html#46f334971b3b75297177daaf93625502">ISODD</a>(nXSize);
<a name="l00484"></a>00484        <span class="keywordtype">int</span> isOddYSize = <a class="code" href="bayer-lcv_8c.html#46f334971b3b75297177daaf93625502">ISODD</a>(nYSize);
<a name="l00485"></a>00485 
<a name="l00486"></a>00486        <span class="keywordtype">int</span> i, nCurIndx;
<a name="l00487"></a>00487 
<a name="l00488"></a>00488        <span class="comment">// Top Border</span>
<a name="l00489"></a>00489        <span class="keywordflow">if</span> (nStartPixY == 1)
<a name="l00490"></a>00490        {
<a name="l00491"></a>00491                <span class="keywordflow">for</span> (i = nStartPixX; i &lt; nXSize; i++)
<a name="l00492"></a>00492                {
<a name="l00493"></a>00493                        pOutData[3 * i + nColOffset] = pOutData[3 * (i + nXSize) + nColOffset];
<a name="l00494"></a>00494                }
<a name="l00495"></a>00495        }
<a name="l00496"></a>00496 
<a name="l00497"></a>00497        <span class="comment">// Left Border</span>
<a name="l00498"></a>00498        <span class="keywordflow">if</span> (nStartPixX == 1)
<a name="l00499"></a>00499        {
<a name="l00500"></a>00500                <span class="keywordflow">for</span> (i = nStartPixY; i &lt; nYSize; i++)
<a name="l00501"></a>00501                {
<a name="l00502"></a>00502                        pOutData[3 * i * nXSize + nColOffset] = pOutData[3 * (i * nXSize + 1) + nColOffset];
<a name="l00503"></a>00503                }
<a name="l00504"></a>00504        }
<a name="l00505"></a>00505 
<a name="l00506"></a>00506        <span class="comment">// Top left corner</span>
<a name="l00507"></a>00507        pOutData[nColOffset] = pInpData[nStartPixY * nXSize + nStartPixX];
<a name="l00508"></a>00508 
<a name="l00509"></a>00509        <span class="comment">// Bottom Border</span>
<a name="l00510"></a>00510        <span class="keywordflow">if</span> (nStartPixY == 0 &amp;&amp; !isOddYSize || nStartPixY == 1 &amp;&amp; isOddYSize)
<a name="l00511"></a>00511        {
<a name="l00512"></a>00512                nCurIndx = (nYSize - 1) * nXSize;
<a name="l00513"></a>00513                <span class="keywordflow">for</span> (i = nStartPixX; i &lt; nXSize; i++)
<a name="l00514"></a>00514                {
<a name="l00515"></a>00515                        pOutData[3 * (nCurIndx + i) + nColOffset] = pOutData[3 * (nCurIndx - nXSize + i) + nColOffset];
<a name="l00516"></a>00516                }
<a name="l00517"></a>00517 
<a name="l00518"></a>00518        }
<a name="l00519"></a>00519 
<a name="l00520"></a>00520        <span class="comment">// Bottom left corner</span>
<a name="l00521"></a>00521        <span class="keywordflow">if</span> (nStartPixY == 0 &amp;&amp; isOddYSize || nStartPixY == 1 &amp;&amp; !isOddYSize)
<a name="l00522"></a>00522                <span class="comment">// Take from last line</span>
<a name="l00523"></a>00523                pOutData[3 * (nYSize-1) * nXSize + nColOffset] = pInpData[(nYSize - 1) * nXSize + nStartPixX];
<a name="l00524"></a>00524        <span class="keywordflow">else</span>
<a name="l00525"></a>00525                <span class="comment">// Take from second last line</span>
<a name="l00526"></a>00526                pOutData[3 * (nYSize-1) * nXSize + nColOffset] = pInpData[(nYSize - 2) * nXSize + nStartPixX];
<a name="l00527"></a>00527 
<a name="l00528"></a>00528 
<a name="l00529"></a>00529        <span class="comment">// Right Border</span>
<a name="l00530"></a>00530        <span class="keywordflow">if</span> (nStartPixX == 0 &amp;&amp; !isOddXSize || nStartPixX == 1 &amp;&amp; isOddXSize)
<a name="l00531"></a>00531        {
<a name="l00532"></a>00532                nCurIndx = nXSize - 1;
<a name="l00533"></a>00533                <span class="keywordflow">for</span> (i = nStartPixY; i &lt; nYSize; i++)
<a name="l00534"></a>00534                {
<a name="l00535"></a>00535                        pOutData[3 * (i * nXSize + nCurIndx) + nColOffset] = pOutData[3 * (i * nXSize + nCurIndx - 1) + nColOffset];
<a name="l00536"></a>00536                }
<a name="l00537"></a>00537        }
<a name="l00538"></a>00538 
<a name="l00539"></a>00539        <span class="comment">// Top right corner</span>
<a name="l00540"></a>00540        <span class="keywordflow">if</span> (nStartPixX == 0 &amp;&amp; isOddXSize || nStartPixX == 1 &amp;&amp; !isOddXSize)
<a name="l00541"></a>00541                <span class="comment">// Take from last column</span>
<a name="l00542"></a>00542                pOutData[3 * (nXSize - 1) + nColOffset] = pInpData[nStartPixY * nXSize + nXSize - 1];
<a name="l00543"></a>00543        <span class="keywordflow">else</span>
<a name="l00544"></a>00544                <span class="comment">// Take from second last column</span>
<a name="l00545"></a>00545                pOutData[3 * (nXSize - 1) + nColOffset] = pInpData[nStartPixY * nXSize + nXSize - 2];
<a name="l00546"></a>00546 
<a name="l00547"></a>00547        <span class="comment">// Bottom right corner</span>
<a name="l00548"></a>00548        <span class="keywordflow">if</span> (nStartPixY == 0 &amp;&amp; isOddYSize || nStartPixY == 1 &amp;&amp; !isOddYSize)
<a name="l00549"></a>00549        {
<a name="l00550"></a>00550                <span class="comment">// Take from last line</span>
<a name="l00551"></a>00551                <span class="keywordflow">if</span> (nStartPixX == 0 &amp;&amp; isOddXSize || nStartPixX == 1 &amp;&amp; !isOddXSize)
<a name="l00552"></a>00552                        <span class="comment">// Take from last column</span>
<a name="l00553"></a>00553                        pOutData[3 * (nXSize * nYSize - 1) + nColOffset] = pInpData[(nYSize - 1) * nXSize + nXSize - 1];
<a name="l00554"></a>00554                <span class="keywordflow">else</span>
<a name="l00555"></a>00555                        <span class="comment">// Take from second last column</span>
<a name="l00556"></a>00556                        pOutData[3 * (nXSize * nYSize - 1) + nColOffset] = pInpData[(nYSize - 1) * nXSize + nXSize - 2];
<a name="l00557"></a>00557        }
<a name="l00558"></a>00558        <span class="keywordflow">else</span>
<a name="l00559"></a>00559        {
<a name="l00560"></a>00560                <span class="comment">// Take from second last line</span>
<a name="l00561"></a>00561                <span class="keywordflow">if</span> (nStartPixX == 0 &amp;&amp; isOddXSize || nStartPixX == 1 &amp;&amp; !isOddXSize)
<a name="l00562"></a>00562                        <span class="comment">// Take from last column</span>
<a name="l00563"></a>00563                        pOutData[3 * (nXSize * nYSize - 1) + nColOffset] = pInpData[(nYSize - 2) * nXSize + nXSize - 1];
<a name="l00564"></a>00564                <span class="keywordflow">else</span>
<a name="l00565"></a>00565                        <span class="comment">// Take from second last column</span>
<a name="l00566"></a>00566                        pOutData[3 * (nXSize * nYSize - 1) + nColOffset] = pInpData[(nYSize - 2) * nXSize + nXSize - 2];
<a name="l00567"></a>00567        }
<a name="l00568"></a>00568 }
<a name="l00569"></a>00569 
<a name="l00570"></a>00570 <span class="comment">// end of file</span>
<a name="l00571"></a>00571 
</pre></div><hr size="1"><address style="text-align: right;"><small>Erzeugt am Thu Dec 13 13:57:31 2007 für LCV Framework von&nbsp;
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.3 </small></address>
</body>
</html>
